package com.fled.itsmbigscreen.service.impl;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fled.itsmbigscreen.utils.TimeTool;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class ReadFileExample  {

    public static void main(String[] args) {
        String filePath = "C:\\Users\\Eric\\Desktop\\HRESS.log";
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            int lineCount = 0;
            int startLine = 800; // 从第10行开始读取
            int currentLine = 1;
            while ((line = br.readLine()) != null) {
                if (currentLine >= startLine) {
                    //                long lineCount = br.lines().();
//                System.out.println(lineCount+":"+line)
//                System.out.println(line);
                    //时间
                    String[] parts = line.split(" ");
                    String time = parts[0];
                    if(!time.contains(".")){
                        time = time.replace("+",".00+");
                    }
                    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
                    Date date = df.parse(time);
                    System.out.println(date);
//                if ()
                    //获取json
                    String[] partsJson = line.split("]: ");
                    String resultJson = partsJson[1].trim();
                    System.out.println(resultJson);
                    currentLine++;
                    System.out.println(lineCount);
                    try {
                        ObjectMapper objectMapper = new ObjectMapper();
                        JsonNode jsonNode = objectMapper.readTree(resultJson);
                        if (jsonNode.get("event_type")!=null){
                            String city = jsonNode.get("event_type").asText();
                            System.out.println(city);
                        }
                    } catch (Exception e) {
//                    e.printStackTrace();
                    } finally {
//                        lineCount++;
                        continue;
                    }

                }
                currentLine++;



//                while (matcher.find()) {
//                    String match = matcher.group(1);
//                    System.out.println(match);
//
//
//                }



            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
